<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Krs_library
{
    public function __construct()
	{
		if (!isset($this->CI))
		{
			$this->CI =& get_instance();

            $this->CI->load->model('siam_akademik/akad_model');
		}
	}

    function check_prasyarat_mk($nim,$kode_prasyarat1=NULL, $kode_prasyarat2=NULL)
    {
        $status = 0;
        if($kode_prasyarat2!=NULL)
		{
            $cek1 = $this->CI->akad_model->viewMkTersedia_cekPrasyarat($kode_prasyarat1, $kode_prasyarat2);

            if($cek1){
              foreach ($cek1 as $value1)
              {
                $cek2   = $this->CI->akad_model->viewDataEnrollment($value1->ID_TERSEDIA,$nim);
                $cek3   = $this->CI->sirak_akad_model->viewDataKonversi($kode_prasyarat2,$nim);
                $status = $status + $cek2 + $cek3;
              }
            }
            else $status = 0;

        }
        else if($kode_prasyarat1!=NULL)
		{
            $cek1 = $this->CI->akad_model->viewMkTersedia_cekPrasyarat($kode_prasyarat1, $kode_prasyarat2);

            if($cek1){
              foreach ($cek1 as $value1)
              {
                $cek2   = $this->CI->akad_model->viewDataEnrollment($value1->ID_TERSEDIA,$nim);
                $cek3   = $this->CI->sirak_akad_model->viewDataKonversi($kode_prasyarat1,$nim);
                $status = $status + $cek2 + $cek3;  
              }
            }
            else $status = 0;


		}
        else $status = 1;

        return $status;
    }

    function cek_bentrok($dataKrsTemp, $dataMkb)
    {
      $bentrok = 0;

      /*Parsing waktu MULAI */
      $parseTime_Temp = explode (":",$dataKrsTemp->MULAI);
      $parseTime_Mkb = explode (":",$dataMkb->MULAI);

      $krsTemp_startHour = intval($parseTime_Temp[0]);
      $krsTemp_startMinute = intval($parseTime_Temp[1]);
      $mkb_startHour = intval($parseTime_Mkb[0]);
      $mkb_startMinute = intval($parseTime_Mkb[1]);

      /*Parsing waktu SELESAI */
      $parseTime_Temp = explode (":",$dataKrsTemp->SELESAI);

      $krsTemp_endHour = intval($parseTime_Temp[0]);
      $krsTemp_endMinute = intval($parseTime_Temp[1]);

      if( ($mkb_startHour == $krsTemp_startHour) AND ($dataKrsTemp->ID_HARI == $dataMkb->ID_HARI) )
      {
         $bentrok = 1;
      }
      else if( ($mkb_startHour > $krsTemp_startHour) AND ($mkb_startHour < $krsTemp_endHour) AND ($dataKrsTemp->ID_HARI == $dataMkb->ID_HARI) )
      {
        if($krsTemp_endMinute != '00')
        {
          if($mkb_startMinute < $krsTemp_endMinute)
          {
             $bentrok = 1;
          }
        }
        else if($krsTemp_endMinute == '00')
        {
          if($mkb_startMinute < 60)
          {
             $bentrok = 1;
          }
        }
      }

      else if( ($mkb_startHour > $krsTemp_startHour) AND ($mkb_startHour == $krsTemp_endHour) AND ($dataKrsTemp->ID_HARI == $dataMkb->ID_HARI) )
      {
        if($mkb_startMinute < $krsTemp_endMinute)
        {
             $bentrok = 1;
        }
      }

      return $bentrok;
    }
}